#!/bin/bash
# Author: fanyongfeng
# 1 0 * * * /bin/bash /root/script/pgsql_log_backup.sh &>> /backup/pgsql_log_backup/backup.log

YESTERDAY=$(date  +"%Y-%m-%d" -d  "-1 days")
BACKUP_DIR="/backup/pgsql_log_backup"
BASEDIR="/data/pgsql/11"
LOG_DIR="${BASEDIR}/data/log/"

mkdir -p ${BACKUP_DIR}

cd ${LOG_DIR} && gzip postgresql-${YESTERDAY}_*.log
mv postgresql-${YESTERDAY}_*.log.gz ${BACKUP_DIR}

find ${BACKUP_DIR} -type f -mtime +180 -name "postgresql-*.log.gz" | xargs -r -n 10 rm -f